package com.data4.order.controller;


import com.data4.feignapi.dto.OrderDTO;
import com.data4.feignapi.dto.Result;
import com.data4.order.service.DOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Forever
 * @since 2024-12-11
 */
@RestController
@RequestMapping("/order")
@Tag(name = "订单管理")
public class DOrderController {
    @Resource
    private DOrderService dOrderService;

    @Operation(summary = "添加订单")
    @PostMapping("/addOrder/{userId}")
    public Result addOrder(@RequestBody OrderDTO orderDTO, @PathVariable Integer userId) {
        return dOrderService.addOrder(orderDTO, userId);
    }

    @Operation(summary = "分页查询订单，按时间降序")
    @GetMapping("/getOrderByTime/{current}/{num}/{userId}")
    public Result getOrderByTime(@PathVariable Long current, @PathVariable Long num
            , @PathVariable Integer userId) {
        return dOrderService.getOrderByTime(current, num, userId);
    }

    @Operation(summary = "分组查询")
    @PostMapping("/getOrderGroup/{userId}")
    public Result getOrderGroup(@RequestBody List<String> groupIds,@PathVariable Integer userId) {
        return dOrderService.getProductGroup(groupIds, userId);
    }

    @Operation(summary = "根据总价钱范围查询")
    @GetMapping("/getOrderByPriceScope/{current}/{num}/{userId}")
    public Result getOrderByPriceScope(@PathVariable("current") Integer current,
                                       @PathVariable("num") Integer num,
                                       @RequestParam(required = false) Integer little,
                                       @RequestParam(required = false) Integer big,
                                       @PathVariable Integer userId) {
        return dOrderService.getOrderByPriceScope(current, num, little, big, userId);
    }

    @Operation(summary = "查询订单详细信息")
    @GetMapping("/getOrder/{orderId}/{userId}")
    public Result getOrder(@PathVariable Integer orderId, @PathVariable Integer userId) {
        return dOrderService.getOrderDetail(orderId, userId);
    }

    @Operation(summary = "根据产品名称模糊查订单")
    @GetMapping("/getOrderByProductName/{ProductCurrent}/{ProductPageNum}/{userId}")
    public Result getOrderByProductName(@PathVariable Integer ProductCurrent,
                                        @PathVariable Integer ProductPageNum,
                                        @RequestParam("productName") String productName,
                                        @PathVariable Integer userId) {
        return dOrderService.getOrderByProductName(ProductCurrent, ProductPageNum,
                productName, userId);
    }
}

